﻿// *****************************************************************************
// **                   Ladenius MediaCenter TVSeries                         **
// ** ----------------------------------------------------------------------- **
// ** (c) 2008 by Jurjen Ladenius                                             **
// *****************************************************************************

#region Using directives
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ladenius.TheTVDB.Entities;
#endregion

namespace Ladenius.TheTVDB.Business {
    /// <summary>
    /// Business logic for seasons
    /// </summary>
    internal static class SeasonHome {

        /// <summary>
        /// Gets the seasons by series ID.
        /// </summary>
        /// <param name="seriesID">The series ID.</param>
        /// <returns>a list of season numbers</returns>
        internal static Dictionary<int, List<Episode>> GetBySeriesID(int seriesID, Language language) {
            List<Episode> episodes = EpisodeHome.GetBySeriesID(seriesID, language);
            return GetFromEpisodeList(episodes);
        }

        /// <summary>
        /// Gets a list of seasons from an episode list.
        /// </summary>
        /// <param name="episodes">The episodes.</param>
        /// <returns>a list of season numbers</returns>
        internal static Dictionary<int, List<Episode>> GetFromEpisodeList(List<Episode> episodes) {
            Dictionary<int, List<Episode>> result = new Dictionary<int, List<Episode>>();
            var query =
                from e in episodes
                group e by e.SeasonNumber into g
                select new { SeasonNumber = g.Key, Episodes = g };
            foreach (var e in query)
                result.Add(e.SeasonNumber, e.Episodes.ToList<Episode>());
            return result;
        }

    }
}
